<template>
    <div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位名称</label>
            </div>
            <div>
                <p>{{detailData.ProjectName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>物资名称</label>
            </div>
            <div>
                <p>{{detailData.GoodsName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>物资类型</label>
            </div>
            <div>
                <p>{{detailData.GoodsType}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>方式</label>
            </div>
            <group>
                <popup-picker :data="modeArr"
                              placeholder='请选择'
                              v-model="modeVal"></popup-picker>
            </group>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>原因</label>
            </div>
            <div>
                <textarea maxlength=“2000”
                          placeholder="请输入"
                          v-model="addData.DetailReason"></textarea>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>时间</label>
            </div>
            <group>
                <datetime v-model="addData.DetailTime"></datetime>
            </group>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>数量</label>
                <i class="iconfont icon-required"></i>
            </div>
            <div>
                <input type="number"
                       placeholder="请输入正整数"
                       v-model="addData.DetailNum">
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>单位</label>
            </div>
            <div>
                <p>{{detailData.GoodsUnit}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>存放地址</label>
            </div>
            <div>
                <p>{{detailData.GoodsPlace}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>责任人</label>
            </div>
            <div>
                <p>{{detailData.GoodsDutyName}}</p>
            </div>
        </div>
        <div class="form-item form-item-style1">
            <div class="label-title">
                <label>联系方式</label>
            </div>
            <div>
                <p>{{detailData.GoodsDutyTel}}</p>
            </div>
        </div>
        <div class="form-item form-item-style2">
            <div class="label-title">
                <label>备注</label>
            </div>
            <div>
                <textarea placeholder="请输入"
                          v-model="addData.DetaiRemark"
                          maxlength=“2000”></textarea>
            </div>
        </div>
        <div class="btns">
            <button class="green width200"
                    @click="submitFn">领用报废登记</button>
        </div>
        <myMenu></myMenu>
    </div>
</template>
<script>
import myMenu from '@/commonComponents/menu'
import formatDate from '@/utils/formatDate'
import { setTimeout } from 'timers'
export default {
    name: 'junkedRegister',
    components: {
        myMenu
    },
    data () {
        return {
            userInfo: {},
            modeArr: [['领用', '报废']],
            modeVal: ['领用'],
            addData: {
                DetaiRemark: '', // 备注
                DetailReason: '', // 原因
                DetailNum: '', // 数量
                DetailTime: formatDate() // 时间
            },
            detailData: {}
        }
    },
    created () {
        this.userInfo = JSON.parse(localStorage.getItem('userInfo')) || {}
        this.detailData = this.$route.params.detail
        console.log(this.detailData)
    },
    methods: {
        submitFn () {
            if (!(/(^[1-9]\d*$)/.test(parseFloat(this.addData.DetailNum)))) {
                this.$vux.toast.text('请输入正整数数量')
                return false
            }
            let params = {
                'allowPaging': true,
                'business': 'AddScrapRegister',
                'data': {
                    'DetaiRemark': this.addData.DetaiRemark, // 备注
                    'DetailDutyName': this.detailData.GoodsDutyName, // 责任人
                    'DetailDutyTel': this.detailData.GoodsDutyTel, // 责任人电话
                    'DetailName': this.detailData.GoodsName, // 物资名称
                    'DetailNum': this.addData.DetailNum, // 数量
                    'DetailReason': this.addData.DetailReason, // 原因
                    'DetailTime': this.addData.DetailTime, // 时间
                    'DetailType': this.detailData.GoodsType, // 物资类型
                    'DetailUnit': this.detailData.GoodsUnit, // 单位
                    'Detailway': this.modeVal[0], // 方式
                    'GoodsId': this.detailData.ID, // 物资列表id
                    'UserName': this.userInfo.username// 执行人员
                },
                'method': '',
                'pageIndex': 0,
                'pageSize': 0,
                'tokenId': '',
                'userId': this.userInfo.userid
            }
            this.$axiosAjax.getConfigJson(params).then((res) => {
                if (res.data.code === 0) {
                    this.$vux.toast.text('提交成功')
                    setTimeout(() => {
                        this.$router.go(-1)
                    }, 500)
                }
            }).catch(() => {

            }).finally(() => {
                this.$vux.loading.hide()
            })
        }
    }
}
</script>
<style scoped>
</style>
